﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebDS;
using WebUS;
using WebDS.CDBNames;
using IP.Core.IPCommon;
using System.Data;
using IP.Core.IPData.DBNames;
using IP.Core.IPData;
using IP.Core.IPUserService;

public partial class ChucNang_Quan_ly_profile_ca_nhan : System.Web.UI.Page
{
    #region Members
    US_DM_NHAN_VIEN m_us_dm_nhan_vien = new US_DM_NHAN_VIEN();
    DS_DM_NHAN_VIEN m_ds_dm_nhan_vien = new DS_DM_NHAN_VIEN();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!this.IsPostBack)
            {
                load_cbo_chuc_vu();
                load_cbo_phong_ban();
                load_data_2_us_object();
                if (Request.QueryString["ID"] != null)
                {
                    
                    decimal v_dc_id = CIPConvert.ToDecimal(Request.QueryString["ID"].ToString());
                    m_us_dm_nhan_vien = new US_DM_NHAN_VIEN(v_dc_id);
                    us_object_2_form();
                }
            }

        }
        catch (Exception v_e)
        {
            this.Response.Write(v_e.ToString());
        }
        
    }
    private void us_object_2_form()
    {
        m_txt_ma_nhan_vien.Text = m_us_dm_nhan_vien.strMA_NHAN_VIEN;
        m_txt_ho_dem.Text = m_us_dm_nhan_vien.strHO_VA_TEN_DEM;
        m_txt_ten_nhan_vien.Text = m_us_dm_nhan_vien.strTEN_NHAN_VIEN;
        m_txt_ngay_sinh.SelectedDate = m_us_dm_nhan_vien.datNGAY_SINH;
        if (m_us_dm_nhan_vien.strGIOI_TINH_YN == "Y")
        {
            m_rdl_gioi_tinh.Items[0].Selected = true;
            m_rdl_gioi_tinh.Items[1].Selected = false;
        }
        else
        {
            m_rdl_gioi_tinh.Items[0].Selected = false;
            m_rdl_gioi_tinh.Items[1].Selected = true;
        }
        m_txt_que_quan.Text = m_us_dm_nhan_vien.strQUE_QUAN;
        m_txt_dia_chi_hien_tai.Text = m_us_dm_nhan_vien.strDIA_CHI_HIEN_TAI;
        m_txt_so_dien_thoai.Text = m_us_dm_nhan_vien.strMOBILE_PHONE;
        m_txt_email_ca_nhan.Text = m_us_dm_nhan_vien.strEMAIL;
        m_txt_email_cong_ty.Text = m_us_dm_nhan_vien.strEMAIL_VANNIEN;
        m_txt_skype.Text = m_us_dm_nhan_vien.strSKYPE;
        m_txt_link_anh.Text = m_us_dm_nhan_vien.strANH_CA_NHAN;
        m_txt_ngay_vao_cong_ty.SelectedDate = m_us_dm_nhan_vien.datNGAY_VAO_CONG_TY;
        m_cbo_phong_ban.SelectedValue=m_us_dm_nhan_vien.dcPHONG_BAN.ToString();
        m_cbo_chuc_vu.SelectedValue=m_us_dm_nhan_vien.dcCHUC_VU.ToString();
        m_txt_so_tai_khoan.Text = m_us_dm_nhan_vien.strSO_TAI_KHOAN;
        m_txt_ngan_hang.Text = m_us_dm_nhan_vien.strTEN_NGAN_HANG;
        m_txt_so_cmt.Text = m_us_dm_nhan_vien.strSO_CMTND;
        m_txt_ngay_cap.SelectedDate = m_us_dm_nhan_vien.datNGAY_CAP;
        m_txt_noi_cap_cmt.Text = m_us_dm_nhan_vien.strNOI_CAP;
        m_txt_ma_so_thue.Text = m_us_dm_nhan_vien.strMA_SO_THUE;
        m_txt_mo_ta_them.Text = m_us_dm_nhan_vien.strDESCRIPTION;
    }
    private void load_cbo_phong_ban()
    {
        US_CM_DM_TU_DIEN v_us_phong_ban = new US_CM_DM_TU_DIEN();
        DS_CM_DM_TU_DIEN v_ds_phong_ban = new DS_CM_DM_TU_DIEN();
        v_us_phong_ban.fill_tu_dien_cung_loai_ds("PHONG_BAN", v_ds_phong_ban);
        m_cbo_phong_ban.DataSource = v_ds_phong_ban.CM_DM_TU_DIEN;
        m_cbo_phong_ban.DataTextField = CM_DM_TU_DIEN.TEN;
        m_cbo_phong_ban.DataValueField = CM_DM_TU_DIEN.ID;
        m_cbo_phong_ban.DataBind();
    }
    private void load_cbo_chuc_vu()
    {
        US_CM_DM_TU_DIEN v_us_chuc_vu = new US_CM_DM_TU_DIEN();
        DS_CM_DM_TU_DIEN v_ds_chuc_vu = new DS_CM_DM_TU_DIEN();
        v_us_chuc_vu.fill_tu_dien_cung_loai_ds("CHUC_VU", v_ds_chuc_vu);
        m_cbo_chuc_vu.DataSource = v_ds_chuc_vu.CM_DM_TU_DIEN;
        m_cbo_chuc_vu.DataTextField = CM_DM_TU_DIEN.TEN;
        m_cbo_chuc_vu.DataValueField = CM_DM_TU_DIEN.ID;
        m_cbo_chuc_vu.DataBind();
    }
    private void form_2_us_object()
    {
        m_us_dm_nhan_vien.strMA_NHAN_VIEN = m_txt_ma_nhan_vien.Text.Trim();
        m_us_dm_nhan_vien.strHO_VA_TEN_DEM = m_txt_ho_dem.Text.Trim();
        m_us_dm_nhan_vien.strTEN_NHAN_VIEN = m_txt_ten_nhan_vien.Text.Trim();
        m_us_dm_nhan_vien.datNGAY_SINH = m_txt_ngay_sinh.SelectedDate;
        if (m_rdl_gioi_tinh.Items[0].Selected == true)
            m_us_dm_nhan_vien.strGIOI_TINH_YN = "Y";
        else
            m_us_dm_nhan_vien.strGIOI_TINH_YN = "N";
        m_us_dm_nhan_vien.strQUE_QUAN = m_txt_que_quan.Text.Trim();
        m_us_dm_nhan_vien.strDIA_CHI_HIEN_TAI = m_txt_dia_chi_hien_tai.Text.Trim();
        m_us_dm_nhan_vien.strMOBILE_PHONE = m_txt_so_dien_thoai.Text.Trim();
        m_us_dm_nhan_vien.strEMAIL = m_txt_email_ca_nhan.Text.Trim();
        m_us_dm_nhan_vien.strEMAIL_VANNIEN = m_txt_email_cong_ty.Text.Trim();
        m_us_dm_nhan_vien.strSKYPE = m_txt_skype.Text.Trim();
        m_us_dm_nhan_vien.strANH_CA_NHAN = m_txt_link_anh.Text.Trim();
        m_us_dm_nhan_vien.datNGAY_VAO_CONG_TY = m_txt_ngay_vao_cong_ty.SelectedDate;
        m_us_dm_nhan_vien.dcPHONG_BAN = CIPConvert.ToDecimal(m_cbo_phong_ban.SelectedValue);
        m_us_dm_nhan_vien.dcCHUC_VU = CIPConvert.ToDecimal(m_cbo_chuc_vu.SelectedValue);
        m_us_dm_nhan_vien.strSO_TAI_KHOAN = m_txt_so_tai_khoan.Text.Trim();
        m_us_dm_nhan_vien.strTEN_NGAN_HANG = m_txt_ngan_hang.Text.Trim();
        m_us_dm_nhan_vien.strSO_CMTND = m_txt_so_cmt.Text.Trim();
        m_us_dm_nhan_vien.datNGAY_CAP = m_txt_ngay_cap.SelectedDate;
        m_us_dm_nhan_vien.strNOI_CAP = m_txt_noi_cap_cmt.Text.Trim();
        m_us_dm_nhan_vien.strMA_SO_THUE = m_txt_ma_so_thue.Text.Trim();
        m_us_dm_nhan_vien.strDESCRIPTION = m_txt_mo_ta_them.Text.Trim();
    }
    private void load_data_2_us_object()
    {
        if (Request.QueryString["ID"] != null)
        {
            hdf_id.Value = Request.QueryString["ID"].ToString();
            m_us_dm_nhan_vien = new US_DM_NHAN_VIEN(CIPConvert.ToDecimal(hdf_id.Value));
        }
    }
    protected void m_btn_cap_nhat_Click(object sender, EventArgs e)
    {
        try
        {
            //Thu thap du lieu
            form_2_us_object();
            //cap nhat trong co so du lieu
            m_us_dm_nhan_vien.dcID = CIPConvert.ToDecimal(Request.QueryString["ID"].ToString());
            m_us_dm_nhan_vien.Update();
            Response.Redirect("/VanNienSysProject/DanhMuc/Danh_sach_nhan_vien.aspx", false);
        }
        catch (Exception v_e)
        {
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
    }

    protected void m_btn_them_moi_Click(object sender, EventArgs e)
    {
        try
        {
            //Thu thap du lieu
            form_2_us_object();
            //Insert vao co so du lieu
            m_us_dm_nhan_vien.Insert();
            Response.Redirect("/VanNienSysProject/DanhMuc/Danh_sach_nhan_vien.aspx", false);
        }
        catch (Exception v_e)
        {
            CSystemLog_301.ExceptionHandle(this, v_e);
        }
    }
    protected void m_btn_xoa_trang_Click(object sender, EventArgs e)
    {
        m_txt_ma_nhan_vien.Text = "";
        m_txt_ho_dem.Text = "";
        m_txt_ten_nhan_vien.Text = "";
        m_txt_que_quan.Text = "";
        m_txt_dia_chi_hien_tai.Text = "";
        m_txt_so_dien_thoai.Text = "";
        m_txt_email_ca_nhan.Text = "";
        m_txt_email_cong_ty.Text = "";
        m_txt_skype.Text = "";
        m_txt_link_anh.Text = "";
        m_cbo_phong_ban.SelectedValue = "";
        m_cbo_chuc_vu.SelectedValue = "";
        m_txt_so_tai_khoan.Text = "";
        m_txt_ngan_hang.Text = "";
        m_txt_so_cmt.Text = "";
        m_txt_noi_cap_cmt.Text = "";
        m_txt_ma_so_thue.Text = "";
        m_txt_mo_ta_them.Text = "";
    }
}